$(function() {
	show();
	getcustomercode();
	

})

/**
 * 获取客户编号以供查询
 */
function getcustomercode(){
	$.ajax({
		url: 'http://localhost:9000/customer/customerinformation/getcustomercode',
		type: 'get',
		dataType: 'json',
		success: function(customerCodes) {
			var content = '<option value="">客户编号</option>';
			for (var i = 0; i < customerCodes.length; i++) {
				var customerCode = customerCodes[i];
				content +='<option value="'+customerCode+'">'+customerCode+'</option>';
			}
			$("#customerCode").html(content);
		}
	})
}


function show() {
	
	var customerCode=$("#customerCode").val();		//"客户编号"
	var customer =$("#customer").val();				//"客户名称"
	var phone =$("#phone").val();					//"电话"></th>
	var fax =$("#fax").val();						//"传真"></th>
	var address =$("#address").val();				//"地址"></th>
	var postCode =$("#postCode").val();				//"邮编"></th>
	var linkman =$("#linkman").val();				//"联系人"></th>
	var linkmanMobile=$("#linkmanMobile").val();				//"联系人手机"></th>
	var customerType=$("#customerType").val();					//"客户类型"></th>
	var enterpriseProperty=$("#enterpriseProperty").val();		//"企业性质"></th>
	var enterpriseSize=$("#enterpriseSize").val();				//"企业规模"></th>
	var email =$("#email").val();					//"电子邮件"></th>
	
	
	
	
	
	$.ajax({
		url: 'http://localhost:9000/customer/customerinformation/findcustomer',
		type: 'get',
		dataType: 'json',
		data:{
			"customerCode":customerCode,
			"customer":customer,
			"phone":phone,
			"address":address,
			"linkman":linkman,
			"linkmanMobile":linkmanMobile,
			"customerType":customerType,
			"enterpriseProperty":enterpriseProperty,
			"enterpriseSize":enterpriseSize,
			"email":email
		},
		success: function(map) {
			var customerInformations=map.customerInformations;
			var content = '';
			for (var i = 0; i < customerInformations.length; i++) {
				var po = customerInformations[i];
				if ((i + 1) % 2 == 0) {
					content += '<tr class="success">';
				} else {
					content += '<tr>';
				}
				content +='<th style="font-size:5px;width:200px;vertical-align:middle;text-align:center">'+po.customerCode+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.customer+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.phone+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.fax+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.address+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.postCode+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.linKman+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.linkmanMobile+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.customerType+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.enterpriseProperty+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.enterpriseSize+'</th>'
					+'<th style="width:100px;vertical-align:middle;text-align:center">'+po.email+'</th>';
				
				content += '<th style="width:80px;vertical-align:middle"><button class="btn" onclick="deleteCustomer('+po.customerCode+')">删除</button></th></tr>';
				
			}
			$("#content").html(content);
		}
	})
	
	// getcustomercode();
}

/**
 * @param {Object} customerCode
 * 删除
 */
function deleteCustomer(customerCode) {
	//服务器端从session中获取当前操作者/管理员姓名

	$.ajax({
		url: 'http://localhost:9000/customer/complaintinformation/delete?customerCode=' + customerCode,
		type: 'get',
		dataType: 'json',
		success: function(map) {
			var msg = map.msg;
			if (msg.indexOf("成功") != -1) {
				alert(msg);
				window.location.href = 'customerInformation.html';
			} else {
				alert(msg + ",请重试");
			}
		}
	})
}

/**
 * @param {Object} ciid
 * 投诉处理方式2：忽视
 */
function ignore(ciid) {
	//服务器端从session中获取当前操作者/管理员姓名

	$.ajax({
		url: 'http://localhost:9000/customer/complaintinformation/ignore?ciid=' + ciid,
		type: 'get',
		dataType: 'json',
		success: function(map) {
			var msg = map.msg;
			if (msg.indexOf("成功") != -1) {
				alert(msg);
				window.location.href = 'complaintInformation.html';
			} else {
				alert(msg + ",请重试");
			}
		}
	})
}
